
var COS = require('cos-nodejs-sdk-v5');
var config = {
    SecretId: 'AKIDslYFqLM2HSix574qncGjwypUxFOM2lDU',
    SecretKey: 'FJLH7qSyNh4Qgp061mPtCKVWLyQktsgO',
    Bucket: 'justtest-1251712170',
    Region: 'ap-chengdu'
};

var cos = new COS({
    // 传入获取临时密钥的接口
    //getSTS: sts.getSTS,
    SecretId: config.SecretId,
    SecretKey: config.SecretKey,
});

exports.upload = function (key, callback) {
    cos.sliceUploadFile({
        Bucket: config.Bucket,
        Region: config.Region,
        Key: key,
        FilePath: `./${key}`
    }, function (err, data) {
        if (err) {
            return callback(err, null)
        }
        callback(null, data.Location)
    });
}
exports.upload2 = function (key, callback) {
    cos.putObject({
        Bucket: config.Bucket,
        Region: config.Region,
        Key: key,
        //FilePath: `./${key}`
    }, function (err, data) {
        if (err) {
            return callback(err, null)
        }
        callback(null, data.Location)
    });
}